package com.shenhaofeng.demo.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.widget.ContentLoadingProgressBar;
import android.view.View;
import android.widget.TextView;

import com.shenhaofeng.app.component.BaseActivity;
import com.shenhaofeng.app.loader.content.ContentLoader;
import com.shenhaofeng.app.loader.content.ContentSource;
import com.shenhaofeng.app.loader.content.OnBindContentListener;
import com.shenhaofeng.app.loader.content.component.ContentLoadingComponent;
import com.shenhaofeng.demo.R;

import java.util.concurrent.TimeUnit;

import rx.Observable;


/**
 * Created by haofeng on 2016/9/28.
 */

public class ContentLoadingActivity extends BaseActivity implements OnBindContentListener<String>, ContentSource<String> {

    private ContentLoader<String> contentLoader;

    private ContentLoadingProgressBar loadingProgressBar;
    private TextView contentView;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        contentLoader = new ContentLoader<>(new ContentLoadingComponent<String>());
        setContentView(R.layout.act_load_content);
        loadingProgressBar = (ContentLoadingProgressBar) findViewById(R.id.loading_view);
        contentView = (TextView) findViewById(R.id.content_view);
        contentLoader.attach(loadingProgressBar, contentView, this, this);
        contentLoader.load();

    }

    @Override
    public void onBindContent(View contentView, String result) {
        this.contentView.setText(result);
    }

    @Override
    public Observable<String> onRequestContent(Bundle args) {
        return Observable.just("ContentLoading").delay(2, TimeUnit.SECONDS);
    }
}
